package com.game.center.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * SpringDoc API文档相关配置
 * Created by macro on 2022/3/4.
 */
@Configuration
public class SpringDocConfig {

    @Autowired
    private SwaggerInfo swaggerInfo;
    private static final String SECURITY_SCHEME_NAME = "BearerAuth";

    @Bean
    public OpenAPI mallTinyOpenAPI() {
        return new OpenAPI()
                .info(new Info().title(swaggerInfo.getTitle())
                        .description(swaggerInfo.getDescription())
                        .version(swaggerInfo.getVersion())
                        .license(new License().name("Apache 2.0")
                        .url(swaggerInfo.getUrl())))
                        .externalDocs(new ExternalDocumentation());
    }

//    @Bean
//    public GroupedOpenApi publicApi() {
//        return GroupedOpenApi.builder()
//                .group("user")
//                .pathsToMatch("/user/**")
//                .build();
//    }

//    @Bean
//    public GroupedOpenApi activityApi() {
//        return GroupedOpenApi.builder()
//                .group("activity")
//                .pathsToMatch("/activity/**")
//                .build();
//    }

//    @Bean
//    public GroupedOpenApi adminApi() {
//        return GroupedOpenApi.builder()
//                .group("admin")
//                .pathsToMatch("/admin/**")
//                .build();
//    }

//    @Bean
//    public OpenAPI mallTinyOpenAPI() {
//        return new OpenAPI()
//                .info(new Info().title(swaggerInfo.getTitle())
//                        .description(swaggerInfo.getDescription())
//                        .version(swaggerInfo.getVersion())
//                        .license(new License().name("Apache 2.0")
//                        .url(swaggerInfo.getUrl())))
//                        .externalDocs(new ExternalDocumentation()
//                        .description(swaggerInfo.getDescription())
//                        .url(swaggerInfo.getUrl()))
//                        .addSecurityItem(new SecurityRequirement().addList(SECURITY_SCHEME_NAME))
//                        .components(new Components()
//                        .addSecuritySchemes(SECURITY_SCHEME_NAME,
//                                new SecurityScheme()
//                                        .name(SECURITY_SCHEME_NAME)
//                                        .type(SecurityScheme.Type.HTTP)
//                                        .scheme("bearer")
//                                        .bearerFormat("JWT")));
//    }

}

